package com.wmlive.hhvideo.heihei.personal.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.wmlive.hhvideo.R;

import com.wmlive.hhvideo.common.base.DcBaseActivity;
import com.wmlive.hhvideo.heihei.beans.main.ShareInfo;
import com.wmlive.hhvideo.heihei.channel.ShareSdkUtils;
import com.wmlive.hhvideo.heihei.login.LoginDialog;
import com.wmlive.hhvideo.utils.ToastUtil;

import java.util.HashMap;

import butterknife.BindView;

/**
 * Created by XueFei on 2017/6/6.
 *
 * 添加好友
 */

public class AddFriendActivity extends DcBaseActivity implements PlatformActionListener {
    @BindView(R.id.btn_add_qq)
    RelativeLayout btnAddQQ;
    @BindView(R.id.btn_add_wechat)
    RelativeLayout btnAddWechat;
    @BindView(R.id.btn_add_sina)
    RelativeLayout btnAddSina;

    private ShareInfo shareInfo;

    // TODO: 2017/6/9 邀请好友数据

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_add_friend;
    }

    @Override
    protected void initData() {
        super.initData();
        setTitle(R.string.user_add_friend_title, true);

        shareInfo = (ShareInfo) getIntent().getSerializableExtra(KEY_PARAM);
        if (null == shareInfo) {
            shareInfo = new ShareInfo();
        }

        btnAddQQ.setOnClickListener(this);
        btnAddWechat.setOnClickListener(this);
        btnAddSina.setOnClickListener(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        dismissLoad();
    }

    @Override
    protected void onSingleClick(View v) {
        if (v.getId() == R.id.btn_add_qq) {
            loading();
            ShareSdkUtils.getInstance().showQQShare(this, shareInfo, this);
        } else if (v.getId() == R.id.btn_add_wechat) {
            loading();
            ShareSdkUtils.getInstance().showWechatShare(this, shareInfo, this);
        } else if (v.getId() == R.id.btn_add_sina) {
            loading();
            ShareSdkUtils.getInstance().showWeiboShare(this, shareInfo, this);
        }
    }

    public static final String KEY_PARAM = "shareinfo";

    public static Intent getCallingIntent(Context context, ShareInfo shareInfo) {
        Intent intent = new Intent(context, AddFriendActivity.class);
        intent.putExtra(KEY_PARAM, shareInfo);
        return intent;
    }

    @Override
    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
        dismissLoad();
        ToastUtil.showToast(R.string.share_suc);
    }

    @Override
    public void onError(Platform platform, int i, Throwable throwable) {
        dismissLoad();
        ToastUtil.showToast(R.string.share_faid);
    }

    @Override
    public void onCancel(Platform platform, int i) {
        dismissLoad();
        ToastUtil.showToast(R.string.share_cancel);
    }
}
